{include file="public/toper"/}
<div class="x-body">
    <form class="layui-form layui-form-pane" action="{:url()}" method="post" id="editForm">
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <select name="pid" class="field-pid" type="select" lay-filter="pid">
                    <option value="0" level="0">顶级菜单</option>
                    {$menu_option}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input field-title" name="title" lay-verify="required" autocomplete="off" placeholder="请输入菜单名称">
            </div>
            <div class="layui-form-mid layui-word-aux">
                必填，长度限制3-24个字节(1个汉字等于3个字节)
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">菜单链接</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input field-url" name="url" lay-verify="required" autocomplete="off" placeholder="请严格按照参考格式填写">
            </div>
            <div class="layui-form-mid layui-word-aux">
                必填，模块格式：模块名/控制器名/方法名，插件直接设置：admin/plugins/run，<span class="red">请留意大小写</span>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" class="field-id" name="id">
                <input type="hidden" name="module" value="{:input('param.mod', 'admin')}">
                <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit">增加</button>
            </div>
        </div>

        <!--<div class="layui-form-item">-->
            <!--<label for="L_repass" class="layui-form-label"></label>-->
            <!--<button  class="layui-btn" lay-filter="admin" lay-submit>增加</button>-->
        <!--</div>-->
    </form>
</div>

<script>
    var formData = {:json_encode($data_info)};
    layui.use(['form'], function() {
        var $ = layui.jquery, form = layui.form;
        if (formData) {
            $('.ass-level').val(parseInt($('.field-pid option:selected').attr('level'))+1);
        }
    });


    layui.use(['jquery'], function() {
        var $ = layui.jquery, input = '';
        /* 修改模式下表单自动赋值 */
        if (formData) {
            for (var i in formData) {
                switch($('.field-'+i).attr('type')) {
                    case 'select':
                        input = $('.field-'+i).find('option[value="'+formData[i]+'"]');
                        input.prop("selected", true);
                        break;
                    case 'radio':
                        input = $('.field-'+i+'[value="'+formData[i]+'"]');
                        input.prop('checked', true);
                        break;
                    case 'checkbox':
                        if (typeof(formData[i]) == 'object') {
                            for(var j in formData[i]) {
                                input = $('.field-'+i+'[value="'+formData[i][j]+'"]');
                                input.prop('checked', true);
                            }
                        } else {
                            input = $('.field-'+i+'[value="'+formData[i]+'"]');
                            input.prop('checked', true);
                        }
                        break;
                    case 'img':
                        input = $('.field-'+i);
                        input.attr('src', formData[i]);
                    default:
                        input = $('.field-'+i);
                        input.val(formData[i]);
                        break;
                }
                if (input.attr('data-disabled')) {
                    input.prop('disabled', true);
                }
                if (input.attr('data-readonly')) {
                    input.prop('readonly', true);
                }
            }
        }
    });
</script>
{include file="public/footer"/}